{
 "cells": [
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Essay Revision"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/LAION-AI/Open-Assistant/blob/main/notebooks/data-augmentation/essay-revision/essay-revision.ipynb)"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {
    "id": "o0lAqmWhsiUe"
   },
   "source": [
    "The goal of this notebook is to use data argumentation to have data on improving essays. The way this is done is by taking a template \"good\" essay and making step by step changes that make it worse and add intructions on how to fix it."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/"
    },
    "executionInfo": {
     "elapsed": 240,
     "status": "ok",
     "timestamp": 1672489678465,
     "user": {
      "displayName": "Graverman",
      "userId": "06659155231973912985"
     },
     "user_tz": -60
    },
    "id": "AFUIjc7xw25A",
    "outputId": "01c13cd7-7252-4948-fd9a-f36919f2214b"
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "[nltk_data] Downloading package wordnet to\n",
      "[nltk_data]     C:\\Users\\Chandru\\AppData\\Roaming\\nltk_data...\n",
      "[nltk_data]   Package wordnet is already up-to-date!\n",
      "[nltk_data] Downloading package omw-1.4 to\n",
      "[nltk_data]     C:\\Users\\Chandru\\AppData\\Roaming\\nltk_data...\n",
      "[nltk_data]   Package omw-1.4 is already up-to-date!\n"
     ]
    }
   ],
   "source": [
    "import nltk\n",
    "\n",
    "nltk.download(\"wordnet\")\n",
    "nltk.download(\"omw-1.4\")\n",
    "import random"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "EcDYv9cnv18v"
   },
   "source": [
    "Put your essay here, [source of the essay used ](https://www.thewisdompost.com/essay/technology-essay/3387#essay-on-technology-for-college-and-university-students-essay-2-750-words)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "executionInfo": {
     "elapsed": 250,
     "status": "ok",
     "timestamp": 1672490871113,
     "user": {
      "displayName": "Graverman",
      "userId": "06659155231973912985"
     },
     "user_tz": -60
    },
    "id": "wvJHUeTJsiC7"
   },
   "outputs": [],
   "source": [
    "essay = \"\"\"\n",
    "We live in a world driven by technology — hardly anyone would argue with you if you said this. Technology, literally meaning the “science of craft”, refers to the collection of techniques, skills, methods, and processes used to produce goods or services or for accomplishing objectives such as scientific investigation. Technology can be embedded in machines enabling them to be used by people even without a detailed knowledge of their inner workings.\n",
    "Technological growth is closely linked to the expansion of scientific research and knowledge. In the last 50 years, thanks to the exponential increases in computing power and microchip design and manufacture, there has been unprecedented innovation and technological growth in nearly every field of human endeavour from health and transport to industrial production and education.\n",
    "\n",
    "It is automotive technology that drives today’s electric and hybrid cars, and which will drive tomorrow’s driverless cars, hover-taxis and space cabs.\n",
    "It is technology that drives the ubiquitous mobile phones that you will now find in the hands of even the poorest of the world’s poor. It is technology that creates hybrid seeds that resist inhospitable climatic conditions and difficult terrain, giving high yields in shorter times.\n",
    "It is advancing medical technology that makes remote surgery, minimally invasive surgery and life-saving cures using stem cell transplants. Technology puts spacecrafts on asteroids and distant planets and lets us see new worlds. Technology splits atoms, revealing their secrets, and gives us ways to exploit them to create energy, quantum storage for data, and virtual reality games.\n",
    "\n",
    "There are people who strongly oppose technology and claim that it spells the death of ‘humanity’, and that we are approaching the day when machines will rule everything. They refer to fans of technology as ‘techies’ or sometimes ‘geeks’. On the other hand, proponents of technology call these people Luddites, a derogatory name for someone who is opposed to industrialisation, automation, computerisation and new technologies in general.\n",
    "Is this true? Is technology really a curse disguised as a blessing? Many believe that the convergence of biotechnology and AI might be the most consequential development of all.\n",
    "\n",
    "In the last five decades, two areas in particular have grown faster than the rest, powered by research and advances in computing power. One is artificial intelligence, or AI; the other is biotechnology. Huge benefits have emerged from each of them for human beings in general, such as self-driving cars — which will dramatically reduce the death rate from road accidents — and robotic surgery, which enables precise, highly efficient and targeted surgical interventions.\n",
    "Yet, visionaries like Yuval Noah Harari, author of the best-selling Homo sapiens and Deus, are now warning that the convergence of biotechnology and AI will irreversibly and unpredictably change both the quality of human life and its challenges in the next few decades. A good example of this is the facial recognition technology that is now present in all photo management programs. The AI in the software is capable of not only spotting the faces in every photograph but also recognising the person by name.\n",
    "This technology has now expanded so that photo apps can recognise cats, dogs, beaches, mountains and cars too. Computers with AI are already correctly identifying human emotions through observing facial expressions and body movements. Some robots are able to mimic human emotions. This is called affective computing, sometimes called artificial emotional intelligence, and refers to the study and development of systems and devices that can recognize, interpret, process, and simulate human affects.\n",
    "\n",
    "The ability to read human emotions is just a step away from predicting human emotions. For example, if a computer attached to a video camera could identify which products a consumer is showing greater interest in or which ones he is really keen to buy, various tactics could be used to influence her to buy it.\n",
    "Activists worry that computers that can understand and anticipate human wishes and desires by scanning their irises and analysing their micro-expressions could also be programmed to exploit and manipulate them.\n",
    "Another very real fear is that humanoid computers with human-like skin, speech, and expressions could jeopardise and dehumanise relationship and create emotional vacuums.\n",
    "\n",
    "An enduring fear of Luddites has always been that computers will rob humans of their livelihood by taking their jobs and doing them more efficiently at lower cost. However, in reality the exact opposite has happened. As computerised machines began taking over mechanical and repetitive human activities, new jobs for people opened up that needs thinking and analytical skills and judgement, or human interpersonal skills. A good example is the worldwide proliferation of call centres.\n",
    "When drones were invented many feared that pilots would soon be redundant. However, few people know that it takes almost 30 people to fly one military drone, and an additional 50 people to analyze and make sense of the data being streamed back by the drone.\n",
    "The US army suffers from a serious shortage of trained, high quality drone pilots; anyone who masters this skill will have a job. But a social scientist warns that in 10 years, it is certain that computers will be flying that drone and humans will be redundant. Equally sure is that some brand new skill requirement will have opened up with advancing technology, calling for new talents.\n",
    "\n",
    "In the 20th century, a young man was supposed to choose a skill, vocation or profession, master it through education and practice, and then earn a living from it till he or she retired. However, the fast-changing nature of technology is making skills obsolete at a higher rate than ever before. To survive, tomorrow young man must keep re-inventing himself and updating his skills continuously. Life could be difficult if every new skill has a shelf life of only a decade or so.\n",
    "Or perhaps one could look at it the other way — and say that changing technology will keep human beings on their toes throughout their life.\n",
    "\n",
    "Technology is the result of human inventiveness. It reflects our evolutionary heritage. We are neither strong like gorillas or tigers, nor fast like cheetahs and hawks, but our brains and thinking powers have given us the greatest edge of any species on the planet. Technology is a result.\n",
    "Technology is either inherently good or bad; it is how we use it that makes it so. The splitting of a hydrogen atom is technology at work. As history has shown us, technology can equally be used to make a nuclear bomb that kills millions — or generate electricity that lights up a million homes.\n",
    "\"\"\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "executionInfo": {
     "elapsed": 5,
     "status": "ok",
     "timestamp": 1672487908938,
     "user": {
      "displayName": "Graverman",
      "userId": "06659155231973912985"
     },
     "user_tz": -60
    },
    "id": "_ttU0Ma8p1_U"
   },
   "outputs": [],
   "source": [
    "instructions = []"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "executionInfo": {
     "elapsed": 232,
     "status": "ok",
     "timestamp": 1672490937384,
     "user": {
      "displayName": "Graverman",
      "userId": "06659155231973912985"
     },
     "user_tz": -60
    },
    "id": "Evaej8oH8VLH"
   },
   "outputs": [],
   "source": [
    "# Make stucture error (shuffle one paragraph with another)\n",
    "essay_paragraphs = essay.split(\"\\n\\n\")  # Splitting a String by newline character (\\n)\n",
    "\n",
    "rand1 = random.randint(0, len(essay_paragraphs) - 1)\n",
    "rand2 = random.randint(0, len(essay_paragraphs) - 1)\n",
    "\n",
    "temp = essay_paragraphs[rand1]\n",
    "essay_paragraphs[rand1] = essay_paragraphs[rand2]\n",
    "essay_paragraphs[rand2] = temp\n",
    "\n",
    "essay = \"\"\n",
    "for i in essay_paragraphs:\n",
    "    essay += i\n",
    "    essay += \"\\n\\n\"\n",
    "\n",
    "instructions.append(\"Fix structure errors in this essay\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "executionInfo": {
     "elapsed": 257,
     "status": "ok",
     "timestamp": 1672490091374,
     "user": {
      "displayName": "Graverman",
      "userId": "06659155231973912985"
     },
     "user_tz": -60
    },
    "id": "HhJXyfy-2OmT"
   },
   "outputs": [],
   "source": [
    "# Make grammar erros (more like: change random words into words of similar meaning)\n",
    "import nltk\n",
    "from nltk.corpus import wordnet\n",
    "import random\n",
    "\n",
    "essay_words = essay.split()\n",
    "\n",
    "for i in range(len(essay_words)):\n",
    "    if random.randint(0, 100) < 30:\n",
    "        suggestion = []\n",
    "        for syn in wordnet.synsets(essay_words[i]):\n",
    "            for l in syn.lemmas():\n",
    "                suggestion.append(l.name())\n",
    "        if suggestion != []:\n",
    "            essay_words[i] = suggestion[random.randint(0, len(suggestion) - 1)]\n",
    "\n",
    "essay = \"\"\n",
    "for i in essay_words:\n",
    "    essay += i\n",
    "    essay += \" \"\n",
    "\n",
    "\n",
    "instructions.append(\"Fix grammar errors in this essay\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "executionInfo": {
     "elapsed": 231,
     "status": "ok",
     "timestamp": 1672490096010,
     "user": {
      "displayName": "Graverman",
      "userId": "06659155231973912985"
     },
     "user_tz": -60
    },
    "id": "delvA6xEzNwV"
   },
   "outputs": [],
   "source": [
    "# Make typos\n",
    "import string\n",
    "import random\n",
    "\n",
    "# you can change the number 60 to change how much corrupted this essay will be\n",
    "for i in range(len(essay) // 60):\n",
    "    rand = random.randint(0, len(essay))\n",
    "    essay = essay[:rand] + random.choice(string.ascii_letters) + essay[rand + 1 :]\n",
    "\n",
    "instructions.append(\"Fix typing errors in this essay\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/"
    },
    "executionInfo": {
     "elapsed": 364,
     "status": "ok",
     "timestamp": 1672484222869,
     "user": {
      "displayName": "Graverman",
      "userId": "06659155231973912985"
     },
     "user_tz": -60
    },
    "id": "4XLAXom_zGsR",
    "outputId": "b741c776-41af-4ad5-8ab7-1825b19018ab"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Fix typing errors in this essay\n"
     ]
    }
   ],
   "source": [
    "# Prints intrcutions (final step)\n",
    "for i in instructions:\n",
    "    print(i)\n",
    "instructions.clear()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "colab": {
   "authorship_tag": "ABX9TyO8HHo9/NuZY8QnCvjrXaYb",
   "provenance": []
  },
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4 (tags/v3.7.4:e09359112e, Jul  8 2019, 20:34:20) [MSC v.1916 64 bit (AMD64)]"
  },
  "vscode": {
   "interpreter": {
    "hash": "25d5c2324055587ceaeef27650c79ce8358ea61d7689f2e0b8ada5d53f85bce4"
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
